adding a util function to calculate decaying reward-rate#65
Conversation
A function to calculate decaying reward-rate timeseries based on discrete reward events. Exponential or hyperbolic kernel options available. tau: should be empirically optimised based on RT of mice etc dt: if too small, even fftconvolve gets very slow. for now default ~50ms that corresponds to FIP effective sampling freqenncy.
| ---------- | ||
| event_times : (N,) array-like | ||
| 1-D array of reward timestamps [s]. | ||
| t_start, t_end : float, optional |
There was a problem hiding this comment.
would there be a reason to change t_start/t_end to a different time? is there value including this as an input?
There was a problem hiding this comment.
For the current usage, not really, but if you have multiple sessions in a recording and want to partially calculate RewRate, this is handy. A good option to have as default=None.
There was a problem hiding this comment.
keep this as it is-- i think we are going to consider multisession analysis in a different capsule. https://github.com/AllenNeuralDynamics/aind-dynamic-foraging-multisession-analysis
|
|
||
| Parameters | ||
| ---------- | ||
| event_times : (N,) array-like |
There was a problem hiding this comment.
should be renamed reward_time if this is specific to reward_rate-- if we just want to convolve this to any type of rate, we should rename this function instead.
There was a problem hiding this comment.
good point. when/if aversive component is integrated, we can do the same excersize to calculate punishment rate, and I was picturing it.
Maybe reward_rate.py, reward_rate() -> event_rate?
There was a problem hiding this comment.
i would make it event_rate instead. it should be general, so long that the tau, hyper_p are not tuned for reward, but for the trial length
There was a problem hiding this comment.
according to your comment above, the latter seems correct.
can you provide documentation for the tau? or can you add a new issue to describe a function to map RT --> tau values? would be nice to add to this PR but we can keep this PR as it is also
There was a problem hiding this comment.
I haven't worked on optimizing tau using RT. I will require a lot of dataset and should be separated from this as it's biology (not a part of util-prep).
will change the name.
|
will lint soonish |
| def reward_rate(event_times, | ||
| t_start=None, | ||
| t_end=None, | ||
| dt=1/20, # matching photometry frame rate |
There was a problem hiding this comment.
move these comments to the comment block below, so folks can see this when they run 'help' with the function
|
we should move this to metrics folder (or even metrics > trial_metrics.py file) since this is a trial metric and the file already calculates response rate (rolling, not convolved reward rate) You can keep the inputs, you'll just need to pull reward events from df_trials (should be See: |
minor filename (reward_rate->event_rate), location (into metrics)
|
discussing with @hanhou he agreed the files should be moved in metric, but forgaing_efficiency should be in a different PR with plenty of notice to folks. |
| from scipy.signal import fftconvolve | ||
|
|
||
|
|
||
| def event_rate( |
There was a problem hiding this comment.
one more- to match foraging_efficiency.py and trial_metrics, this function should be called compute_event_rate instead
rachelstephlee
left a comment
There was a problem hiding this comment.
looks good-- i ran it and it matches to what you've shown in our group chats.
i would fix the naming of the function and the final linting (add comment at the start of the file) and we can merge.
rachelstephlee
left a comment
There was a problem hiding this comment.
approved, thank you!
A function to calculate decaying reward-rate time-series based on discrete reward events.
Exponential or hyperbolic kernel options are available.
fftconvolvegets very slow. For now default ~50ms that corresponds to FIP effective sampling frequency, works with a reasonable computational load.